<!-- 三列布局容器 -->
<div class="three-column-layout">
    <!-- 第一列：专家信息 -->
    <div class="column column-1">
        <!-- 专家基本信息 -->
        <div class="expert-info-section">
            <div class="expert-header">
                <div class="expert-avatar">
                    <% if (expert.avatar_url) { %>
                        <img src="<%= expert.avatar_url %>" alt="<%= expert.nickname %>" class="avatar">
                    <% } else { %>
                        <div class="avatar avatar-placeholder">
                            <%= expert.nickname ? expert.nickname.charAt(0) : '?' %>
                        </div>
                    <% } %>
                </div>
                <div class="expert-details">
                    <h2 class="expert-name"><%= expert.nickname %></h2>
                    <div class="expert-domain">
                        <span class="domain-tag"><%= expert.domain ? expert.domain.name : '未知领域' %>·模型</span>
                    </div>
                    <% if (expert.bio) { %>
                        <p class="expert-bio"><%= expert.bio %></p>
                    <% } %>
                </div>
            </div>
        </div>

        <!-- 经典案例 -->
        <% if (expert.classic_cases && expert.classic_cases.length > 0) { %>
        <div class="classic-cases-section">
            <h3 class="section-title">经典案例</h3>
            <div class="cases-list">
                <% expert.classic_cases.forEach(function(caseItem, index) { %>
                    <div class="case-item">
                        <div class="case-question">
                            <h4>用户问题</h4>
                            <p><%= caseItem.question %></p>
                        </div>
                        <div class="case-answer">
                            <h4>专家回答</h4>
                            <p><%= caseItem.answer %></p>
                        </div>
                    </div>
                <% }); %>
            </div>
        </div>
        <% } %>
    </div>

    <!-- 第二列：领域欢迎语和前置条件 -->
    <div class="column column-2">
        <div class="welcome-section">
            <h3 class="section-title">咨询须知</h3>

            <!-- 领域欢迎语 -->
            <% if (expert.domain && expert.domain.welcome_message_1) { %>
                <div class="welcome-message">
                    <p><%= expert.domain.welcome_message_1 %></p>
                </div>
            <% } %>

            <!-- 前置条件表单 -->
            <% if (expert.domain && expert.domain.precondition_config && expert.domain.precondition_config.fields) { %>
                <div class="precondition-form">
                    <form id="preconditionForm">
                        <% expert.domain.precondition_config.fields.forEach(function(field) { %>
                            <div class="form-group">
                                <label class="form-label">
                                    <%= field.label %>
                                    <% if (field.required) { %>
                                        <span class="required">*</span>
                                    <% } %>
                                </label>

                                <% if (field.type === 'radio') { %>
                                    <div class="radio-group">
                                        <% field.options.forEach(function(option, optionIndex) { %>
                                            <label class="radio-label">
                                                <input type="radio" name="<%= field.name %>" value="<%= option %>" <%= field.required ? 'required' : '' %>>
                                                <span class="radio-text"><%= option %></span>
                                            </label>
                                        <% }); %>
                                    </div>
                                <% } else if (field.type === 'checkbox') { %>
                                    <div class="checkbox-group">
                                        <% field.options.forEach(function(option, optionIndex) { %>
                                            <label class="checkbox-label">
                                                <input type="checkbox" name="<%= field.name %>" value="<%= option %>">
                                                <span class="checkbox-text"><%= option %></span>
                                            </label>
                                        <% }); %>
                                    </div>
                                <% } else if (field.type === 'date') { %>
                                    <input type="date" name="<%= field.name %>" class="form-input" <%= field.required ? 'required' : '' %>>
                                <% } else if (field.type === 'number') { %>
                                    <input type="number" name="<%= field.name %>" class="form-input" <%= field.required ? 'required' : '' %>>
                                <% } else { %>
                                    <input type="text" name="<%= field.name %>" class="form-input" <%= field.required ? 'required' : '' %>>
                                <% } %>
                            </div>
                        <% }); %>

                        <button type="button" id="confirmPreconditions" class="confirm-btn">确认信息</button>
                    </form>
                </div>
            <% } else { %>
                <div class="no-preconditions">
                    <button type="button" id="skipPreconditions" class="confirm-btn">开始咨询</button>
                </div>
            <% } %>
        </div>
    </div>

    <!-- 第三列：提问区域 -->
    <div class="column column-3" id="questionColumn" style="display: none;">
        <div class="question-section">
            <h3 class="section-title">向 <%= expert.nickname %> 提问</h3>

            <!-- 领域欢迎语2 -->
            <% if (expert.domain && expert.domain.welcome_message_2) { %>
                <div class="welcome-message-2">
                    <p><%= expert.domain.welcome_message_2 %></p>
                </div>
            <% } %>



            <!-- 提问表单 -->
            <div class="question-form">
                <div class="form-group">
                    <label class="form-label">请输入您的问题</label>
                    <textarea id="questionInput" class="question-textarea" placeholder="请详细描述您的问题..." rows="6"></textarea>
                </div>

                <button type="button" id="submitQuestion" class="submit-btn">
                    <span class="btn-text">提交问题</span>
                    <span class="btn-loading" style="display: none;">正在生成答案...</span>
                </button>
            </div>

            <!-- 答案显示区域 -->
            <div id="answerSection" class="answer-section" style="display: none;">
                <h4>专家回答</h4>
                <div id="answerContent" class="answer-content"></div>

                <!-- 评分区域 -->
                <div class="rating-section">
                    <h5>请为这次咨询评分</h5>
                    <div class="rating-buttons">
                        <button type="button" class="rating-btn" data-rating="1">不满意</button>
                        <button type="button" class="rating-btn" data-rating="3">一般</button>
                        <button type="button" class="rating-btn" data-rating="5">满意</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- CSS样式 -->
<style>
    .three-column-layout {
        display: grid;
        grid-template-columns: 400px 400px 1fr;
        gap: 24px;
        min-height: calc(100vh - 120px);
        padding: 0;
        margin: 0;
    }

    .column {
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        padding: 24px;
        overflow-y: auto;
        height: calc(100vh - 120px);
    }

    .column-1 {
        border-left: 4px solid #667eea;
    }

    .column-2 {
        border-left: 4px solid #28a745;
    }

    .column-3 {
        border-left: 4px solid #ffc107;
        min-width: 0; /* 允许flex收缩 */
    }

    .expert-info-section {
        margin-bottom: 24px;
    }

    .expert-header {
        display: flex;
        gap: 16px;
        align-items: flex-start;
        margin-bottom: 20px;
    }

    .expert-avatar {
        flex-shrink: 0;
    }

    .avatar {
        width: 80px;
        height: 80px;
        border-radius: 50%;
        object-fit: cover;
        border: 3px solid #667eea;
    }

    .avatar-placeholder {
        background: #667eea;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 32px;
        font-weight: 600;
    }

    .expert-details {
        flex: 1;
    }

    .expert-name {
        font-size: 24px;
        font-weight: 600;
        color: #333;
        margin: 0 0 8px 0;
    }

    .expert-domain {
        margin-bottom: 12px;
    }

    .domain-tag {
        background: #667eea;
        color: white;
        padding: 4px 12px;
        border-radius: 16px;
        font-size: 12px;
        font-weight: 500;
    }

    .expert-bio {
        color: #666;
        line-height: 1.6;
        margin: 0;
    }

    .section-title {
        font-size: 18px;
        font-weight: 600;
        color: #333;
        margin: 0 0 16px 0;
        padding-bottom: 8px;
        border-bottom: 2px solid #f0f0f0;
    }

    .classic-cases-section {
        margin-top: 24px;
    }

    .cases-list {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    .case-item {
        background: #f8f9fa;
        border-radius: 8px;
        padding: 16px;
        border: 1px solid #e9ecef;
    }

    .case-question,
    .case-answer {
        margin-bottom: 12px;
    }

    .case-question:last-child,
    .case-answer:last-child {
        margin-bottom: 0;
    }

    .case-question h4 {
        font-size: 14px;
        font-weight: 600;
        color: #007bff;
        margin: 0 0 4px 0;
    }

    .case-answer h4 {
        font-size: 14px;
        font-weight: 600;
        color: #28a745;
        margin: 0 0 4px 0;
    }

    .case-question p,
    .case-answer p {
        font-size: 13px;
        line-height: 1.5;
        color: #333;
        margin: 0;
    }

    .welcome-message {
        background: #e8f5e8;
        border-radius: 8px;
        padding: 16px;
        margin-bottom: 20px;
        border-left: 4px solid #28a745;
    }

    .welcome-message p {
        margin: 0;
        color: #333;
        line-height: 1.6;
    }

    .welcome-message-2 {
        background: #fff3e0;
        border-radius: 8px;
        padding: 16px;
        margin-bottom: 20px;
        border-left: 4px solid #ffc107;
    }

    .welcome-message-2 p {
        margin: 0;
        color: #333;
        line-height: 1.6;
        font-weight: 500;
    }

    .precondition-form {
        background: #f8f9fa;
        border-radius: 8px;
        padding: 20px;
        border: 1px solid #e9ecef;
    }

    .precondition-form h4 {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0 0 16px 0;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-label {
        display: block;
        font-size: 14px;
        font-weight: 600;
        color: #333;
        margin-bottom: 8px;
    }

    .required {
        color: #dc3545;
        margin-left: 4px;
    }

    .radio-group,
    .checkbox-group {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .radio-label,
    .checkbox-label {
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 14px;
        color: #333;
        cursor: pointer;
        font-weight: normal;
    }

    .radio-label input,
    .checkbox-label input {
        margin: 0;
    }

    .form-input {
        width: 100%;
        padding: 8px 12px;
        border: 1px solid #ddd;
        border-radius: 4px;
        font-size: 14px;
    }

    .form-input:focus {
        outline: none;
        border-color: #28a745;
        box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.2);
    }

    .confirm-btn {
        width: 100%;
        background: #28a745;
        color: white;
        border: none;
        padding: 12px 24px;
        border-radius: 6px;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: background-color 0.2s;
        margin-top: 16px;
    }

    .confirm-btn:hover {
        background: #218838;
    }

    .confirm-btn:disabled {
        background: #6c757d;
        cursor: not-allowed;
    }

    .no-preconditions {
        text-align: center;
        padding: 40px 20px;
    }

    .precondition-confirmation {
        background: #e8f5e8;
        border-radius: 8px;
        padding: 20px;
        border: 1px solid #c3e6c3;
        border-left: 4px solid #28a745;
    }

    .confirmation-content h4 {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0 0 16px 0;
    }

    .confirmation-list {
        list-style: none;
        padding: 0;
    }

    .confirmation-list li {
        padding: 8px 0;
        border-bottom: 1px solid #d4edda;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .confirmation-list li:last-child {
        border-bottom: none;
    }

    .confirmation-list li strong {
        color: #155724;
        font-weight: 600;
        flex: 0 0 auto;
        margin-right: 12px;
    }

    .confirmation-list li span {
        color: #333;
        flex: 1;
        text-align: right;
        word-break: break-word;
    }

    .precondition-summary {
        background: #e8f5e8;
        border-radius: 8px;
        padding: 16px;
        margin-bottom: 20px;
        border-left: 4px solid #28a745;
    }

    .precondition-summary h4 {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0 0 12px 0;
    }

    .precondition-summary ul {
        margin: 0;
        padding-left: 20px;
    }

    .precondition-summary li {
        color: #333;
        line-height: 1.5;
        margin-bottom: 4px;
    }

    .question-form {
        margin-bottom: 24px;
    }

    .question-textarea {
        width: 100%;
        padding: 12px;
        border: 1px solid #ddd;
        border-radius: 6px;
        font-size: 14px;
        line-height: 1.5;
        resize: vertical;
        height: 70px;
    }

    .question-textarea:focus {
        outline: none;
        border-color: #ffc107;
        box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.2);
    }

    .submit-btn {
        width: 100%;
        background: #ffc107;
        color: #333;
        border: none;
        padding: 12px 24px;
        border-radius: 6px;
        font-size: 16px;
        font-weight: 600;
        cursor: pointer;
        transition: background-color 0.2s;
        margin-top: 16px;
    }

    .submit-btn:hover {
        background: #e0a800;
    }

    .submit-btn:disabled {
        background: #6c757d;
        color: white;
        cursor: not-allowed;
    }

    .answer-section {
        margin-top: 24px;
        padding-top: 24px;
        border-top: 2px solid #f0f0f0;
    }

    .answer-section h4 {
        font-size: 18px;
        font-weight: 600;
        color: #333;
        margin: 0 0 16px 0;
    }

    .answer-content {
        background: #f8f9fa;
        border-radius: 8px;
        padding: 20px;
        border-left: 4px solid #ffc107;
        margin-bottom: 20px;
    }

    .answer-content p {
        margin: 0;
        line-height: 1.8;
        color: #333;
        white-space: pre-wrap;
    }

    .rating-section {
        text-align: center;
    }

    .rating-section h5 {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0 0 16px 0;
    }

    .rating-buttons {
        display: flex;
        gap: 12px;
        justify-content: center;
    }

    .rating-btn {
        padding: 8px 16px;
        border: 1px solid #ddd;
        border-radius: 20px;
        background: white;
        color: #333;
        font-size: 14px;
        cursor: pointer;
        transition: all 0.2s;
    }

    .rating-btn:hover {
        border-color: #ffc107;
        background: #ffc107;
        color: #333;
    }

    .rating-btn.selected {
        background: #ffc107;
        border-color: #ffc107;
        color: #333;
    }

    /* 响应式设计 */
    @media (max-width: 1400px) {
        .three-column-layout {
            grid-template-columns: 350px 350px 1fr;
        }
    }

    @media (max-width: 1024px) {
        .three-column-layout {
            grid-template-columns: 1fr;
            gap: 16px;
            min-height: auto;
        }

        .column {
            padding: 16px;
            height: auto;
            max-height: 80vh;
        }

        .expert-header {
            flex-direction: column;
            text-align: center;
        }

        .rating-buttons {
            flex-direction: column;
            align-items: center;
        }
    }

    @media (max-width: 768px) {
        .avatar {
            width: 60px;
            height: 60px;
        }

        .avatar-placeholder {
            font-size: 24px;
        }

        .expert-name {
            font-size: 20px;
        }

        .section-title {
            font-size: 16px;
        }
    }
</style>

<!-- JavaScript功能 -->
<script>
    // 全局变量
    let preconditionData = {};
    let currentQuestionId = null;
    let apiMode = 'remote'; // 'remote'

    // DOM元素
    const preconditionForm = document.getElementById('preconditionForm');
    const confirmBtn = document.getElementById('confirmPreconditions');
    const skipBtn = document.getElementById('skipPreconditions');
    const questionColumn = document.getElementById('questionColumn');
    const preconditionSummary = document.getElementById('preconditionSummary');
    const questionInput = document.getElementById('questionInput');
    const submitBtn = document.getElementById('submitQuestion');
    const answerSection = document.getElementById('answerSection');
    const answerContent = document.getElementById('answerContent');


    // 确认前置条件
    function confirmPreconditions() {
        console.log('confirmPreconditions 函数被调用');
        console.log('preconditionForm:', preconditionForm);

        if (preconditionForm) {
            // 验证必填字段
            const requiredFields = preconditionForm.querySelectorAll('[required]');
            let isValid = true;

            for (let field of requiredFields) {
                if (field.type === 'radio') {
                    const radioGroup = preconditionForm.querySelectorAll(`[name="${field.name}"]`);
                    const isChecked = Array.from(radioGroup).some(radio => radio.checked);
                    if (!isChecked) {
                        isValid = false;
                        break;
                    }
                } else if (!field.value.trim()) {
                    isValid = false;
                    break;
                }
            }

            if (!isValid) {
                alert('请填写所有必填项');
                return;
            }

            // 收集表单数据
            const formData = new FormData(preconditionForm);
            preconditionData = {};

            // 先收集所有数据
            for (let [key, value] of formData.entries()) {
                if (preconditionData[key]) {
                    // 处理多选框
                    if (Array.isArray(preconditionData[key])) {
                        preconditionData[key].push(value);
                    } else {
                        preconditionData[key] = [preconditionData[key], value];
                    }
                } else {
                    preconditionData[key] = value;
                }
            }

            console.log('收集到的表单数据:', preconditionData);

            // 禁用表单
            const inputs = preconditionForm.querySelectorAll('input, select, textarea');
            inputs.forEach(input => input.disabled = true);
            confirmBtn.disabled = true;
            confirmBtn.textContent = '已确认';
        }

        // 在第二列显示确认信息，替换表单
        showPreconditionConfirmation();

        // 显示第三列
        questionColumn.style.display = 'block';

        // 滚动到第三列
        questionColumn.scrollIntoView({ behavior: 'smooth' });
    }

    // 跳过前置条件
    function skipPreconditions() {
        preconditionData = {};
        showPreconditionConfirmation();
        questionColumn.style.display = 'block';
        questionColumn.scrollIntoView({ behavior: 'smooth' });
    }

    // 在第二列显示前置条件确认信息
    function showPreconditionConfirmation() {
        console.log('showPreconditionConfirmation 函数被调用');
        const preconditionForm = document.getElementById('preconditionForm');
        console.log('preconditionForm:', preconditionForm);
        if (!preconditionForm) {
            console.log('未找到 preconditionForm');
            return;
        }

        let confirmationHtml = '';

        if (Object.keys(preconditionData).length > 0) {
            confirmationHtml = `
                <div class="precondition-confirmation">
                    <div class="confirmation-content">
                        <ul class="confirmation-list">
            `;

            for (let [key, value] of Object.entries(preconditionData)) {
                const displayValue = Array.isArray(value) ? value.join(', ') : value;
                confirmationHtml += `<li><strong>${getFieldLabel(key)}:</strong> <span>${displayValue}</span></li>`;
            }

            confirmationHtml += `
                        </ul>
                    </div>
                </div>
            `;
        } else {
            confirmationHtml = `
                <div class="precondition-confirmation">
                    <div class="confirmation-content">
                        -
                    </div>
                </div>
            `;
        }

        console.log('替换 preconditionForm 内容');
        console.log('confirmationHtml:', confirmationHtml);

        // 只替换表单内容，保留其他元素
        preconditionForm.outerHTML = confirmationHtml;
        console.log('确认信息显示完成');
    }

    // 获取字段标签
    function getFieldLabel(fieldName) {
        const fieldLabels = {
            <% if (expert.domain && expert.domain.precondition_config && expert.domain.precondition_config.fields) { %>
                <% expert.domain.precondition_config.fields.forEach(function(field) { %>
                    '<%= field.name %>': '<%= field.label %>',
                <% }); %>
            <% } %>
        };
        return fieldLabels[fieldName] || fieldName;
    }



    // 提交问题
    async function submitQuestion() {
        const question = questionInput.value.trim();
        if (!question) {
            alert('请输入您的问题');
            return;
        }

        // 禁用提交按钮
        submitBtn.disabled = true;
        submitBtn.querySelector('.btn-text').style.display = 'none';
        submitBtn.querySelector('.btn-loading').style.display = 'inline';

        try {
            // 准备请求数据
            console.log('表单数据:', preconditionData);
            console.log('问题:', question);

            const requestData = {
                expert_id: '<%= expert.external_expert_id || expert.id %>',
                question: question,
                form_data: preconditionData,
                temperature: 0.7
            };

            console.log('发送的完整数据:', JSON.stringify(requestData, null, 2));

            // 使用远程API (7882端口) 并添加认证
            const response = await fetch('http://47.106.80.190:7882/chat?' + Date.now(), {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'x-api-key': 'bizhi_dev_1234567890abcdef1234567890ab',
                    'User-Agent': 'bizhi-system-agent/1.0'
                },
                cache: 'no-cache',
                body: JSON.stringify(requestData)
            });
            const apiUsed = '远程API (7882端口)';

            console.log('响应状态:', response.status);
            console.log('响应头:', Object.fromEntries(response.headers.entries()));

            if (!response.ok) {
                // 尝试获取错误详情
                let errorText = '';
                try {
                    const errorData = await response.json();
                    errorText = JSON.stringify(errorData, null, 2);
                    console.log('错误详情:', errorData);
                } catch (e) {
                    errorText = await response.text();
                    console.log('错误文本:', errorText);
                }
                throw new Error(`HTTP ${response.status}: ${response.statusText}\n详情: ${errorText}`);
            }

            const result = await response.json();
            console.log('API响应:', result); // 调试日志

            if (result.success === true) {
                // 处理API响应格式
                let answer = '';
                let expertInfo = '';

                // 远程API (7882端口) 响应格式
                answer = result.ai_response?.content || '专家正在思考中...';
                expertInfo = `使用API: ${apiUsed} | 专家: ${result.expert_info?.expert_name || '<%= expert.nickname %>'} (${result.expert_info?.expert_nickname || ''})`;

                // 显示答案和API信息
                answerContent.innerHTML = `
                    <div style="background: #e3f2fd; padding: 10px; border-radius: 4px; margin-bottom: 15px; font-size: 12px; color: #1976d2;">
                        ${expertInfo}
                    </div>
                    <div ltyle="shiteaspacp:wpr -wrap; ne-height: 1.2;2font-size: 14px;">${answer}</div>
                `;
                answerSection.style.display = 'block';
                currentQuestionId = Date.now(); // 使用时间戳作为临时ID

                // 滚动到答案区域
                answerSection.scrollIntoView({ behavior: 'smooth' });
            } else {
                console.error('API调用失败:', result);
                let errorMsg = '生成答案失败：';
                if (result.message) {
                    errorMsg += result.message;
                } else if (result.error) {
                    errorMsg += result.error;
                } else if (result.detail) {
                    errorMsg += result.detail;
                } else {
                    errorMsg += '未知错误';
                }
                alert(errorMsg);
            }
        } catch (error) {
            console.error('提交问题失败:', error);
            alert('提交问题失败，请检查网络连接或稍后再试');
        } finally {
            // 恢复提交按钮
            submitBtn.disabled = false;
            submitBtn.querySelector('.btn-text').style.display = 'inline';
            submitBtn.querySelector('.btn-loading').style.display = 'none';
        }
    }

    // 评分（简化处理，仅在前端记录）
    function rateAnswer(rating) {
        if (!currentQuestionId) {
            alert('无法评分：未找到问答记录');
            return;
        }

        // 更新评分按钮状态
        document.querySelectorAll('.rating-btn').forEach(btn => {
            btn.classList.remove('selected');
            btn.disabled = true;
        });

        const selectedBtn = document.querySelector(`[data-rating="${rating}"]`);
        if (selectedBtn) {
            selectedBtn.classList.add('selected');
        }

        // 显示感谢信息
        alert('评分成功，感谢您的反馈！');

        // 可以在这里添加发送评分到子系统P的逻辑
        console.log('用户评分:', rating, '问答ID:', currentQuestionId);
    }

    // 事件监听
    document.addEventListener('DOMContentLoaded', function() {
        console.log('DOM加载完成');
        console.log('confirmBtn:', confirmBtn);

        // 确认前置条件按钮
        if (confirmBtn) {
            console.log('绑定确认按钮事件');
            confirmBtn.addEventListener('click', function() {
                console.log('确认按钮被点击');
                confirmPreconditions();
            });
        } else {
            console.log('未找到确认按钮');
        }

        // 跳过前置条件按钮
        if (skipBtn) {
            skipBtn.addEventListener('click', skipPreconditions);
        }

        // 提交问题按钮
        if (submitBtn) {
            submitBtn.addEventListener('click', submitQuestion);
        }

        // API模式选择
        if (apiModeSelect) {
            apiModeSelect.addEventListener('change', function() {
                apiMode = this.value;
                apiStatus.style.display = 'none';
            });
        }



        // 评分按钮
        document.querySelectorAll('.rating-btn').forEach(btn => {
            btn.addEventListener('click', function() {
                const rating = parseInt(this.getAttribute('data-rating'));
                rateAnswer(rating);
            });
        });

        // 回车键提交问题
        if (questionInput) {
            questionInput.addEventListener('keydown', function(e) {
                if (e.key === 'Enter' && e.ctrlKey) {
                    submitQuestion();
                }
            });
        }
    });
</script>
